package com.songcha.module_mine.ui.adapter

import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.songcha.library_common.util.GlideUtil
import com.songcha.library_common.util.dp2px
import com.songcha.module_mine.R
import com.songcha.module_mine.bean.MyBookCommentDataBean
import com.songcha.module_mine.databinding.MineItemMessageMycommentBinding

class MessageMyCommentAdapter<DB:ViewDataBinding>(list:MutableList<MyBookCommentDataBean.MyBookCommentBean>):BaseQuickAdapter<MyBookCommentDataBean.MyBookCommentBean,BaseDataBindingHolder<DB>>(
    R.layout.mine_item_message_mycomment,list) {

    init {
        addChildClickViewIds(R.id.mine_iv_del_comment)
    }

    override fun convert(holder: BaseDataBindingHolder<DB>, item: MyBookCommentDataBean.MyBookCommentBean) {
        val db=holder.dataBinding as MineItemMessageMycommentBinding
        db.mineTvMessageTitle.text=item.author
        db.mineTvComment.text=item.content
        GlideUtil.loadNetImage(db.mineIvMessage,item.avatar)
        GlideUtil.loadNetImage(db.mineIvThumb,item.cover)
        db.mineTvBookName.text=item.bookName
        db.mineTvAuthor.text=item.author

        if(holder.absoluteAdapterPosition==0 || holder.absoluteAdapterPosition==data.size){
            db.root.layoutParams=db.root.layoutParams.apply {
                this as ViewGroup.MarginLayoutParams
                topMargin=12.dp2px()
                bottomMargin=12.dp2px()
            }
        }else{
            db.root.layoutParams=db.root.layoutParams.apply {
                this as ViewGroup.MarginLayoutParams
                topMargin=0
                bottomMargin=0
            }
        }

    }


}